package com.torry.workflow.service.web.controller;

import com.torry.workflow.api.user.api.OrgApi;
import com.torry.workflow.api.user.entity.Org;
import com.torry.workflow.common.base.result.Result;
import org.apache.dubbo.config.annotation.DubboReference;
import org.springframework.web.bind.annotation.*;

import java.util.ArrayList;
import java.util.List;

@RestController
@RequestMapping("/org")
public class OrgController {
    @DubboReference
    private OrgApi orgApi;
    @PostMapping("save")
    public Result saveOrgInfo(@RequestBody Org org){
        orgApi.saveOrg(org);
        return Result.saveSuccess();
    }

    @GetMapping("tree")
    public Result tree(){
        return Result.selectSuccess(orgApi.getOrgTree());
    }

    @DeleteMapping("delete/{ids}")
    public Result delete(@PathVariable String ids) {
        String[] idArr = ids.split(",");
        List<Integer> idList = new ArrayList<>();
        for (String s : idArr) {
            idList.add(Integer.parseInt(s));
        }
        orgApi.deleteOrgByIds(idList);
        return Result.delSuccess();
    }
}
